import re


def url_fmt(host: str) -> str:
    """
    格式化，主要是给ip地址补上url
    :param host:
    :return:
    """
    protocol_prefix = re.match(r'^(http|https)://[^\n\r]+', host)
    if protocol_prefix:
        return host
    else:
        protocol = 'http'
        return '%s://%s' % (protocol, host)


def url_builder(host: str, port: int = 80) -> str:
    """
    按照host和port构建一个标准url
    :param host:
    :param port:
    :return:
    """
    protocol_prefix = re.match(r'^(http|https)://[^\n\r]+', host)
    if protocol_prefix:
        return '%s:%s' % (host, port)
    else:
        protocol = 'http'
        if port == 443:
            protocol = 'https'
        return '%s://%s:%s' % (protocol, host, port)
